﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KD.Sms.DAL.DAS
{
    public class Main
    {

        /// <summary>
        /// 本类的唯一实例
        /// </summary>
        private static Main OWNER = null;
        private static string _strDasUser = System.Configuration.ConfigurationManager.AppSettings["DasUser"];
        private static string _strDasPassword = System.Configuration.ConfigurationManager.AppSettings["DasPassWord"];
        /// <summary>
        /// 私有构造函数
        /// </summary>
        private Main()
        {

        }

        /// <summary>
        /// 获取类的唯一实例
        /// </summary>
        /// <returns></returns>
        public static Main Instance
        {
            get
            {
                if (Main.OWNER == null)
                {
                    Main.OWNER = new Main();
                }
                return Main.OWNER;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lpr"></param>
        /// <param name="flowid"></param>
        /// <param name="tlen"></param>
        /// <param name="twidth"></param>
        /// <param name="len"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="postion"></param>
        /// <param name="date"></param>
        /// <param name="mine"></param>
        /// <param name="material"></param>
        /// <param name="supplier"></param>
        /// <param name="transport"></param>
        /// <param name="machine"></param>
        /// <param name="pail"></param>
        /// <param name="poscount"></param>
        /// <param name="layout"></param>
        /// <param name="begintime"></param>
        /// <param name="endtime"></param>
        /// <param name="state"></param>
        /// <param name="weight"></param>
        /// <param name="rfid"></param>
        /// <param name="pos"></param>
        /// <param name="imgbegin"></param>
        /// <param name="imgend"></param>
        /// <returns></returns>
        public bool DoUploadSamplingInfo(string lpr, string flowid, decimal tlen, decimal twidth, decimal len, decimal width, decimal height, string postion
           , string date, string mine, string material, string supplier, string transport
            , string machine, int pail, int poscount, int layout, string begintime, string endtime, int state, decimal weight, string rfid, string pos, string imgbegin, string imgend,string _strSparestr1)
        {
            try
            {
                KD.DAS.Cliecnt.RequestResult model = KD.DAS.Cliecnt.Main.Instance.DoUploadSamplingInfo(lpr, flowid, tlen, twidth, len, width, height, postion,//车辆信息
                    date, mine, material, supplier, transport,//运输信息
                    machine, pail, poscount, layout, begintime, endtime, state, weight, rfid, pos,imgbegin,imgend,//采样信息
                    _strDasUser, _strDasPassword, _strSparestr1);
                if (model != null && !model.En_Success)
                {
                    FormHelper.ApplicationShow(UI.MsgType.Error, model.En_ErrInfo);
                    return false;
                }
                else
                {
                    return model.En_Success;
                }
            }
            catch (Exception ex)
            {
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, "KD.Sms.DAL.DAS.Main.DoUploadSamplingInfo()");
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, ex.ToString());
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lpr"></param>
        /// <param name="flowid"></param>
        /// <param name="tlen"></param>
        /// <param name="twidth"></param>
        /// <param name="len"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="postion"></param>
        /// <param name="mine"></param>
        /// <param name="material"></param>
        /// <param name="supplier"></param>
        /// <param name="transport"></param>
        /// <param name="DasUser"></param>
        /// <param name="DasPassword"></param>
        /// <returns></returns>
        public bool DoSaveDataLocal(string lpr, string flowid, decimal tlen, decimal twidth, decimal len, decimal width, decimal height, string postion, string mine, string material, string supplier, string transport)
        {
            try
            {
                KD.DAS.Cliecnt.RequestResult model = KD.DAS.Cliecnt.Main.Instance.DoSaveDataLocal(lpr, flowid, tlen, twidth, len, width, height, postion, mine, material, supplier, transport, _strDasUser, _strDasPassword);
                if (model != null && !model.En_Success)
                {
                    FormHelper.ApplicationShow(UI.MsgType.Error, model.En_ErrInfo);
                    return false;
                }
                else
                {
                    return model.En_Success;
                }
            }
            catch (Exception ex)
            {
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, "KD.Sms.DAL.DAS.Main.DoSaveDataLocal()");
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, ex.ToString());
                return false;
            }
        }


        /// <summary>
        /// 发送采样请求
        /// </summary>
        /// <param name="car"></param>
        /// <returns></returns>
        public KD.DAS.Cliecnt.SamplingInfo DoSendRequest(string car)
        {
            try
            {
                return KD.DAS.Cliecnt.Main.Instance.DoSendRequest(car, _strDasUser, _strDasPassword);
            }
            catch (Exception ex)
            {
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, "KD.Sms.DAL.DAS.Main.DoSendRequest()");
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, ex.ToString());
                return null;
            }
        }

        /// <summary>
        /// 提交采样开始
        /// </summary>
        /// <param name="matchine"></param>
        /// <param name="processid"></param>
        /// <param name="poscount"></param>
        /// <param name="samplingtype"></param>
        /// <param name="samplinglayout"></param>
        /// <param name="pail"></param>
        /// <param name="points"></param>
        /// <param name="DasUser"></param>
        /// <param name="DasPassword"></param>
        /// <returns></returns>
        public bool DoSubmitSamplingBegin(string matchine, string processid, int poscount, int samplingtype, int samplinglayout, int pail, string points, out string samplingid)
        {
            samplingid = string.Empty;
            try
            {
                KD.DAS.Cliecnt.RequestResult model = KD.DAS.Cliecnt.Main.Instance.DoSubmitSamplingBegin(matchine, processid, poscount, samplingtype, samplinglayout, pail, points, _strDasUser, _strDasPassword);
                if (model != null && !model.En_Success)
                {
                    FormHelper.ApplicationShow(UI.MsgType.Error, model.En_ErrInfo);
                    return false;
                }
                else
                {
                    samplingid = model.En_Value.ToString();
                    return model.En_Success;
                }
            }
            catch (Exception ex)
            {
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, "KD.Sms.DAL.DAS.Main.DoSubmitSamplingBegin()");
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, ex.ToString());
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="samplingid"></param>
        /// <param name="DasUser"></param>
        /// <param name="DasPassword"></param>
        /// <returns></returns>
        public bool DoSubmitSamplingEnd(string samplingid)
        {
            try
            {
                KD.DAS.Cliecnt.RequestResult model = KD.DAS.Cliecnt.Main.Instance.DoSubmitSamplingEnd(samplingid, _strDasUser, _strDasPassword);
                if (model != null && !model.En_Success)
                    FormHelper.ApplicationShow(UI.MsgType.Error, model.En_ErrInfo);
                return model.En_Success;
            }
            catch (Exception ex)
            {
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, "KD.Sms.DAL.DAS.Main.DoSubmitSamplingEnd()");
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, ex.ToString());
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="samplingid"></param>
        /// <param name="pail"></param>
        /// <param name="weight"></param>
        /// <param name="rfid"></param>
        /// <param name="DasUser"></param>
        /// <param name="DasPassword"></param>
        /// <returns></returns>
        public bool DoSubmitSamplingWeight(string samplingid, string pail, string weight, string rfid)
        {
            try
            {
                KD.DAS.Cliecnt.RequestResult model = KD.DAS.Cliecnt.Main.Instance.DoSubmitSamplingWeight(samplingid, pail, weight, rfid, _strDasUser, _strDasPassword);
                if (model != null && !model.En_Success)
                    FormHelper.ApplicationShow(UI.MsgType.Error, model.En_ErrInfo);
                return model.En_Success;
            }
            catch (Exception ex)
            {
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, "KD.Sms.DAL.DAS.Main.DoSubmitSamplingWeight()");
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, ex.ToString());
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="samplingid"></param>
        /// <param name="index"></param>
        /// <param name="block"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="DasUser"></param>
        /// <param name="DasPassword"></param>
        /// <returns></returns>
        public bool DoUpdateSamplingPoint(string samplingid, int index, int block, int x, int y, int z)
        {
            try
            {
                KD.DAS.Cliecnt.RequestResult model = KD.DAS.Cliecnt.Main.Instance.DoUpdateSamplingPoint(samplingid, index, block, x, y, z, _strDasUser, _strDasPassword);
                if (model != null && !model.En_Success)
                    FormHelper.ApplicationShow(UI.MsgType.Error, model.En_ErrInfo);
                return model.En_Success;
            }
            catch (Exception ex)
            {
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, "KD.Sms.DAL.DAS.Main.DoUpdateSamplingPoint()");
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, ex.ToString());
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="samplingid"></param>
        /// <param name="isbegin"></param>
        /// <param name="iamge"></param>
        /// <param name="DasUser"></param>
        /// <param name="DasPassword"></param>
        /// <returns></returns>
        public bool DoSubmitSamplingImage(string samplingid, bool isbegin, string iamge)
        {
            try
            {
                KD.DAS.Cliecnt.RequestResult model = KD.DAS.Cliecnt.Main.Instance.DoSubmitSamplingImage(samplingid, isbegin, iamge, _strDasUser, _strDasPassword);
                if (model != null && !model.En_Success)
                    FormHelper.ApplicationShow(UI.MsgType.Error, model.En_ErrInfo);
                return model.En_Success;
            }
            catch (Exception ex)
            {
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, "KD.Sms.DAL.DAS.Main.DoSubmitSamplingImage()");
                Log.LogHelper.DoWriteLogTypeSubitem(Log.LogType.Error, Log.LogSubitem.DAS, ex.ToString());
                return false;
            }
        }





    }
}
